package com.xu.cloud.common.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xuguan
 * @since 2024/7/4
 */
@Configuration
@AutoConfigureAfter(value = {RedissonAutoConfiguration.class})
@ConditionalOnClass(value = {RedissonClient.class})
public class RedissonConfig {

    public static final String XU_CLOUD_BLOOM_FILTER_NAME = "xu-cloud-bloomFilter";

    @Bean
    public RBloomFilter<String> redissonClient(RedissonClient redissonClient) {
        final RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter(XU_CLOUD_BLOOM_FILTER_NAME);
        // 预计插入的元素个数为100000000, 误判率的上限为0.01(1%)
        bloomFilter.tryInit(100000000L, 0.01F);
        return bloomFilter;
    }
}
